public class Demo1 {
}
class Solution {
    /**
     0:当天不持有股票
     1:当天持有股票
     */
    public int maxProfit(int[] prices) {
        int n = prices.length;
        int f0 = 0;
        int f1 = Integer.MIN_VALUE;
        for(int i=0; i<n; i++){
            int new_f0 = Math.max(f0,f1+prices[i]);
            f1 = Math.max(f1,f0-prices[i]);
            f0 = new_f0;
        }
        return f0;
    }
}
class Solution1 {
    /**
     0:当天不持有股票
     1:当天持有股票
     */
    public int maxProfit(int[] prices) {
        int n = prices.length;
        int[][] dp = new int[n+1][2];
        dp[0][0] = 0;
        dp[0][1] = Integer.MIN_VALUE;
        for(int i=0; i<n; i++){
            dp[i+1][0] = Math.max(dp[i][0],dp[i][1]+prices[i]);
            dp[i+1][1] = Math.max(dp[i][1],dp[i][0]-prices[i]);
        }
        return dp[n][0];
    }
}
